
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.Employee;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Employee entities.
 * 
 */
@Repository("EmployeeDAO")

@Transactional
public class EmployeeDAOImpl extends AbstractJpaDao<Employee> implements EmployeeDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			Employee.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new EmployeeDAOImpl
	 *
	 */
	public EmployeeDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findEmployeeByRfidContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByRfidContaining(String rfid) throws DataAccessException {

		return findEmployeeByRfidContaining(rfid, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByRfidContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByRfidContaining(String rfid, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByRfidContaining", startResult, maxRows, rfid);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByLogOn
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByLogOn(Boolean logOn) throws DataAccessException {

		return findEmployeeByLogOn(logOn, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByLogOn
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByLogOn(Boolean logOn, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByLogOn", startResult, maxRows, logOn);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByNumberContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByNumberContaining(String number) throws DataAccessException {

		return findEmployeeByNumberContaining(number, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByNumberContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByNumberContaining(String number, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByNumberContaining", startResult, maxRows, number);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeBySexContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeBySexContaining(String sex) throws DataAccessException {

		return findEmployeeBySexContaining(sex, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeBySexContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeBySexContaining(String sex, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeBySexContaining", startResult, maxRows, sex);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeBySex
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeBySex(String sex) throws DataAccessException {

		return findEmployeeBySex(sex, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeBySex
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeBySex(String sex, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeBySex", startResult, maxRows, sex);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByBirthday
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByBirthday(java.util.Calendar birthday) throws DataAccessException {

		return findEmployeeByBirthday(birthday, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByBirthday
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByBirthday(java.util.Calendar birthday, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByBirthday", startResult, maxRows, birthday);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByPrimaryKey
	 *
	 */
	@Transactional
	public Employee findEmployeeByPrimaryKey(Integer id) throws DataAccessException {

		return findEmployeeByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByPrimaryKey
	 *
	 */

	@Transactional
	public Employee findEmployeeByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEmployeeByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.Employee) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findEmployeeByPassword
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByPassword(String password) throws DataAccessException {

		return findEmployeeByPassword(password, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByPassword
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByPassword(String password, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByPassword", startResult, maxRows, password);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllEmployees
	 *
	 */
	@Transactional
	public Set<Employee> findAllEmployees() throws DataAccessException {

		return findAllEmployees(-1, -1);
	}

	/**
	 * JPQL Query - findAllEmployees
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findAllEmployees(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllEmployees", startResult, maxRows);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByMemo
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByMemo(String memo) throws DataAccessException {

		return findEmployeeByMemo(memo, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByMemo
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByMemo(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByMemo", startResult, maxRows, memo);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeById
	 *
	 */
	@Transactional
	public Employee findEmployeeById(Integer id) throws DataAccessException {

		return findEmployeeById(id, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeById
	 *
	 */

	@Transactional
	public Employee findEmployeeById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEmployeeById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.Employee) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findEmployeeByPasswordContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByPasswordContaining(String password) throws DataAccessException {

		return findEmployeeByPasswordContaining(password, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByPasswordContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByPasswordContaining(String password, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByPasswordContaining", startResult, maxRows, password);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByState
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByState(Boolean state) throws DataAccessException {

		return findEmployeeByState(state, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByState
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByState(Boolean state, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByState", startResult, maxRows, state);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByRfid
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByRfid(String rfid) throws DataAccessException {

		return findEmployeeByRfid(rfid, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByRfid
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByRfid(String rfid, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByRfid", startResult, maxRows, rfid);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByMemoContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByMemoContaining(String memo) throws DataAccessException {

		return findEmployeeByMemoContaining(memo, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByMemoContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByMemoContaining(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByMemoContaining", startResult, maxRows, memo);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByNameContaining
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByNameContaining(String name) throws DataAccessException {

		return findEmployeeByNameContaining(name, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByNameContaining(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByName
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByName(String name) throws DataAccessException {

		return findEmployeeByName(name, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByName", startResult, maxRows, name);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * JPQL Query - findEmployeeByNumber
	 *
	 */
	@Transactional
	public Set<Employee> findEmployeeByNumber(String number) throws DataAccessException {

		return findEmployeeByNumber(number, -1, -1);
	}

	/**
	 * JPQL Query - findEmployeeByNumber
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Employee> findEmployeeByNumber(String number, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEmployeeByNumber", startResult, maxRows, number);
		return new LinkedHashSet<Employee>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Employee entity) {
		return true;
	}
}
